using System;
using Caliburn.Micro;
using EmraldClient.Properties;

namespace EmraldClient
{
  public class EnterPasswordViewModel : MyScreen
  {
    private static readonly ILog Log = LogManager.GetLog(typeof(EnterPasswordViewModel));
    private readonly IEmraldService _connection;

    public EnterPasswordViewModel(IEmraldService connection)
    {
      _connection = connection;
      var name = Settings.Default.UserName;
      if (!string.IsNullOrWhiteSpace(name))
        _userName = name;

      var pwd = Settings.Default.Password;
      if (!string.IsNullOrWhiteSpace(pwd))
        _password = pwd;
    }

    #region ' UserName Property '

    public string UserName
    {
      get { return _userName; }
      set
      {
        if (_userName == value) return;
        _userName = value;
        NotifyOfPropertyChange(() => UserName);
      }
    }

    private string _userName;

    #endregion

    #region ' Password Property '

    public string Password
    {
      get { return _password; }
      set
      {
        if (_password == value) return;
        _password = value;
        NotifyOfPropertyChange(() => Password);
      }
    }

    private string _password;

    #endregion

    public void Logon()
    {
      OnDone(EventArgs.Empty);
    }

    public void LogonAsGuest()
    {
      UserName = "guest";
      Password = "";

      OnDone(EventArgs.Empty);
    }
  }
}